﻿using System;
using System.Collections.Generic;
using SobrietyEngine.UDMF;
using SobrietyEngine.Actor;
using SobrietyEngine.Components;
using SobrietyEngine.Components.Common;
using SobrietyEngine.Components.Graphic;
using SobrietyEngine.Physics;
using SobrietyEngine.Scene;
using Microsoft.Xna.Framework;

namespace SobrietyEngine.Actor.Builders.UDMF
{
    public class UDMFSectorBldr:BaseActorBuilder
    {
        public static IActor Build(IScene scene, List<Vertex> contour, float z, string texture, Matrix srt, Boolean reverse)
        {
            IActor actor = scene.CreateEmptyActor();
            actor.AttachComponent(new PositionCmp(new Vector3(0, 0, 0)));

            //convert vertex to vector3[]
            Vector3[] poly = new Vector3[contour.Count];
            for (int i = 0; i < contour.Count; ++i)
            {
                poly[i] = new Vector3(contour[i].Position, z);
            }

            if (reverse)
            {
                texture = "textures/GreenGrid";
            }
            else
            {
                texture = "textures/RedGrid";
            }

            //if (texture == String.Empty || texture == "-")
            //texture = "textures/GreenGrid";

            TexturedPolygonCmp tpoly = new TexturedPolygonCmp(texture, poly, srt, reverse);
            actor.AttachComponent(tpoly);
            actor.Initialize();

            return actor;
        }
    }
}
